package com.example.blogsystem.model;

import com.example.blogsystem.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T> {
    private Integer code;//状态码
    private String errMag;//错误信息
    private T data;//数据
    //成功时返回的数据
    public static <T> Result success(T data) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setData(data);
        return result;
    }
    //失败返回的失败信息
    public static <T> Result fail(String errMag) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setErrMag(errMag);
        return result;
    }
    public static <T> Result nologin(T data, String errMag) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.No_Login.getCode());
        result.setData(data);
        result.setErrMag("未登录");
        return result;
    }

    public static <T> Result fail(Integer code, String errMag) {
        Result result = new Result();
        result.setCode(code);
        result.setErrMag(errMag);
        return result;
    }
}
